//
//  VenueVipViewController.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/26.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "VenueVipViewController.h"
#import "VenueVipModel.h"
#import "VenueVipTableViewCell.h"
#import "ChineseString.h"
#import "VenueVipTableHeadView.h"
//#import "VenueModel.h"
#import "AddVenueVipViewController.h"
#import "VipInfoMainViewController.h"
#import "UIViewAdditions.h"
#import "VipBottomAlertView.h"
#import "VipFilterView.h"
#import "SearchView.h"
#import "BirthNoticeViewController.h"
#import "RenewalCardRemindViewController.h"
#import "CZQOderDetailView.h"
#import "CZQMsterPageVC.h"
@interface VenueVipViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{
    
    NSString *selectStr;
    
    int startIndex;
    
    int pageSize;
    
    //保存总数据的
    NSArray *_datArr;
}
/**
 师傅关注数据源
 */
@property(nonatomic,strong)NSMutableArray *attendArr;

@property(nonatomic,weak)UITableView *tableView;

@property(nonatomic,weak)SearchView *searchView;

@property(nonatomic,weak)VenueVipTableHeadView *headView;

@property(nonatomic,strong) UserAccount *userAcount;

@property(nonatomic,strong) NSMutableArray *indexArray;

@property(nonatomic,strong) NSMutableArray *letterResultArr;

@property (nonatomic, strong) UILabel *sectionTitleView;

@property (nonatomic, strong) NSMutableArray *stringsToSort;

@property (nonatomic, strong) NSMutableArray *dataArray;

@property(nonatomic,strong)NoDataView *noDataView;

@property (nonatomic, strong) NSMutableDictionary *dataDict;

@property (nonatomic, strong) NSTimer *timer;

//过滤字段
@property (nonatomic,strong)NSMutableDictionary *filterDict;

//底部View
@property (nonatomic,strong)VipBottomAlertView *vipBottomAlertView;

@end

@implementation VenueVipViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    if ([self.title isEmptyString]) {
        self.title = @"会员";
    }
    
    
    
    self.userAcount = [UserAccount account];
    
    self.view.backgroundColor = BackGroundColor;
    
    self.indexArray = [ChineseString IndexArray:self.stringsToSort];
    
    self.letterResultArr = [ChineseString LetterSortArray:self.stringsToSort];
    
    //右侧图片 icon_nbarmore
    if ([self.userAcount.MasterType integerValue] == 0) {
        UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"icon_navadd"]
                                                                                   imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(addVipMember)];
        self.navigationItem.rightBarButtonItem = rightButtonItem;
    }
    
    
    
    [self createSubView];
    
    [NotificationCenter addObserver:self selector:@selector(loadStartData) name:@"ReloadVipMember" object:nil];
}

-(void)createSubView{
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.showsVerticalScrollIndicator = NO;
    tableView.estimatedRowHeight = 200;
    [tableView registerClass:[VenueVipTableViewCell class] forCellReuseIdentifier:@"VenueVipTableViewCell"];
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    tableView.backgroundColor = CSClearColor;
    //修改索引颜色
    tableView.sectionIndexColor = CSColorFromRGB(0x0a0a0a);//修改右边索引字体的颜色
    tableView.sectionIndexTrackingBackgroundColor = CSClearColor;//修改右边索引点击颜色
    [self.view addSubview:tableView];
    
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    footer.automaticallyHidden = YES;
    
    MyTableHead *mj_head = [MyTableHead headerWithRefreshingTarget:self refreshingAction:@selector(loadStartData)];
    tableView.mj_header = mj_head;
    tableView.mj_footer = footer;
    [tableView.mj_header beginRefreshing];
    [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.edges.mas_equalTo(self.view);
        
    }];
    self.tableView = tableView;
    
    VenueVipTableHeadView *tableHeadView = [[VenueVipTableHeadView alloc] init];
    
    tableHeadView.verLineView.hidden = YES;
    [self.view addSubview:tableHeadView];
    self.headView = tableHeadView;
    tableHeadView.searchView.delegate = self;
    [tableHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(tableView);
        
        make.left.width.mas_equalTo(self.view);
    }];
    
    
    
    if ([self.userAcount.MasterType isEqualToString:@"1"]) {
        
        [tableHeadView.sortBtn setImage:nil];
        [tableHeadView.sortBtn setTitle:nil];
        [tableHeadView.sortRegBtn setImage:nil];
        [tableHeadView.sortRegBtn setTitle:nil];
        [tableHeadView.fitBtn setImage:nil];
        [tableHeadView.fitBtn setTitle:nil];
        
        [tableHeadView.sortBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        
        [tableHeadView.sortRegBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        
        [tableHeadView.fitBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        
        
        
    }else
    {
        [tableHeadView.sortBtn addTarget:self action:@selector(birthBtnClick)];
        [tableHeadView.sortRegBtn addTarget:self action:@selector(sortRegBtnClick)];
        [tableHeadView.fitBtn addTarget:self action:@selector(filterBtnClick)];
    }
    
    [tableHeadView setNeedsLayout];
    [tableHeadView layoutIfNeeded];
    
    tableView.tableHeaderView = tableHeadView;
    
    
    //默认字母排序
    selectStr = @"characterSort";
    
//    UIButton *addVenueVipBtn = [[UIButton alloc] init];
//    [addVenueVipBtn setImage:@"icon_navadd"];
//    [addVenueVipBtn addTarget:self action:@selector(addVipMember)];
//    [self.view addSubview:addVenueVipBtn];
//    [addVenueVipBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
//
//        make.right.mas_equalTo(self.view).offset(-10);
//
//        make.bottom.mas_equalTo(self.view).offset(-30);                
//    }];
}

#pragma mark 下拉
-(void)loadStartData{
    
    startIndex = 1;
    
    pageSize = 20;
    
    [self loadData];
}

#pragma mark 上拉
-(void)loadMoreData{
    
    if ([self.title isEqualToString:@"会员"]) {
        startIndex = startIndex + 1;
    }
    
    
    [self loadData];
}

-(NSMutableArray *)attendArr
{
    if (!_attendArr) {
        
        _attendArr = [NSMutableArray array];
        
    }
    
    return _attendArr;
}

-(void)loadData{
    
    //Get_MemberList
    
    [MBProgressHUD showMessage:@"加载中..." toView:self.view];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    NSString *url ;
    
    //默认字母排序
    selectStr = @"characterSort";
    
    if ([self.title isEqualToString:@"我的徒弟"]) {
        
        url = Get_GetMemberListDataByMaster;
        
        if (![self.headView.searchView.text isEmptyString]) {
            
            [params setObject:self.headView.searchView.text forKey:@"MemberName"];
            
            [params setObject:self.headView.searchView.text forKey:@"CellPhone"];
            
            selectStr = @"search";
        }
        [params setValue :[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"] forKey:@"MasterID"];
        
        
    }else if ([self.title isEqualToString:@"我的粉丝"]) {
        
        [self getMasterAttentList];
        
        url = Get_Activity_ActivityFollowList;
        
        
        [params setValue :[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"] forKey:@"ToMemberID"];
        
        [params setValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"MasterType"] forKey:@"ToUserType"];
        
    }
    else if ([self.title isEqualToString:@"会员"]) {
        
        url = Get_MemberList;
        
        [params setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"ShopID"] forKey:@"ShopID"];
        
        
        
        if (![self.headView.searchView.text isEmptyString]) {
            
            [params setObject:self.headView.searchView.text forKey:@"MemberName"];
            
            [params setObject:self.headView.searchView.text forKey:@"CellPhone"];
            
            selectStr = @"search";
        }
        
        
        [params setObject:[NSString stringWithFormat:@"%d",startIndex] forKey:@"page"];
        
        [params setObject:[NSString stringWithFormat:@"%d",pageSize] forKey:@"rows"];
        
        if (self.filterDict.count > 0) {
            [params setValuesForKeysWithDictionary:self.filterDict];
            selectStr = @"search";
        }
        
        
        [self.filterDict removeAllObjects];
        
    }
    
    
    
    
    [HTTPTool GET:url parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@==%@",responseObject,params);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSMutableArray *resultArray = [responseObject objectForKey:@"rows"];
                  
                  if (resultArray.count > 0) {
                      
                      [self.tableView.mj_header endRefreshing];
                      
                      [self.tableView.mj_footer endRefreshing];
                  }
                  else{
                      
                      [self.tableView.mj_header endRefreshing];
                      
                      [self.tableView.mj_footer endRefreshingWithNoMoreData];
                  }
                  
                  self.noDataView = [NoDataView shareInstance];
                  
                  [self.noDataView hideInView:self.view];
                  
                  //搜索删除以前数据
                  if ([selectStr isEqualToString:@"search"]) {
                      [self.stringsToSort removeAllObjects];
                      
                      [self.dataDict removeAllObjects];
                  }
                  
                  if (startIndex == 1) {
                      
                      self.dataArray = [NSMutableArray arrayWithArray:resultArray];
                      
                      if (self.dataArray.count == 0) {

                          self.noDataView = [NoDataView shareInstance];

                          [self.noDataView showInView:self.view];
                      }

                      [self.stringsToSort removeAllObjects];
                      
                      [self.dataDict removeAllObjects];
                      
                      for (NSDictionary *dict in self.dataArray) {
                          
                          if ([self.title isEqualToString:@"我的徒弟"]) {
                              
                              //后面取数据要用到ID，但是ID不影响排序
                              [self.stringsToSort addObject:[NSString stringWithFormat:@"%@\\%@",[dict objectForKey:@"RealName"],[dict objectForKey:@"ID"]]];
                              
                          }else if ([self.title isEqualToString:@"我的粉丝"])
                          {
                              //后面取数据要用到ID，但是ID不影响排序
                              [self.stringsToSort addObject:[NSString stringWithFormat:@"%@\\%@",[dict objectForKey:@"Name"],[dict objectForKey:@"ID"]]];
                              
                          }
                          else if ([self.title isEqualToString:@"会员"])
                          {
                              //后面取数据要用到ID，但是ID不影响排序
                              [self.stringsToSort addObject:[NSString stringWithFormat:@"%@\\%@",[dict objectForKey:@"Name"],[dict objectForKey:@"ID"]]];
                          }
                          
                          
                      }
                  }
                  else{
                      
                      [self.dataArray addObjectsFromArray:resultArray];
                      
                      for (NSDictionary *dict in resultArray) {
                          
                          //后面取数据要用到ID，但是ID不影响排序
                          [self.stringsToSort addObject:[NSString stringWithFormat:@"%@\\%@",[dict objectForKey:@"Name"],[dict objectForKey:@"ID"]]];
                      }
                  }
                  
                  self.indexArray = [ChineseString IndexArray:self.stringsToSort];
//
                  self.letterResultArr = [ChineseString LetterSortArray:self.stringsToSort];
//
                  
                  for (NSDictionary *dict in self.dataArray) {
                      
                      NSString *key = [NSString stringWithFormat:@"%@",[dict objectForKey:@"ID"]];
                      
                      [self.dataDict setObject:dict forKey:key];
                  }
                  
                  
                  _datArr = [self.dataArray copy];
                  
                  NSLog(@"%@ ==%@",_datArr,self.dataArray);
                  
                  VenueVipTableHeadView *tableHeadView = (VenueVipTableHeadView *)self.tableView.tableHeaderView;
                  
                  tableHeadView.vipCountLabel1.text = [NSString stringWithFormat:@"%@人",[[responseObject objectForKey:@"total"] stringValue]];
                  
                  [self.tableView reloadData];
              }
              
          }
     
          failure:^(NSError *error){
              [self.tableView.mj_header endRefreshing];
              
              [self.tableView.mj_footer endRefreshing];
              [MBProgressHUD hideHUDForView:self.view];
          }];
}


#pragma mark - 获取师傅关注列表判断自己是否关注
-(void)getMasterAttentList
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    NSString *userId = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"];
    
    [params setValue:userId  forKey:@"MemberID"];
    [params setValue:[[NSUserDefaults standardUserDefaults]objectForKey:@"MasterType" ]  forKey:@"UserType"];
    
    
    
    
    [HTTPTool GET:Get_Activity_ActivityFollowList parameters:params
     
          success:^(id responseObject){
              
              [MBProgressHUD hideHUDForView:self.view];
              
              NSLog(@"%@=%@",responseObject,userId);
              
              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                  
                  NSArray *resultArray = [responseObject objectForKey:@"rows"];
                  
                  if (resultArray.count == 0) {
                      return ;
                  }
                  
                  
                  
                  [self.attendArr addObjectsFromArray:resultArray];
                  
                  [self.tableView reloadData];
                  
                  
              }
              
          }
     
          failure:^(NSError *error){
              
              [self.tableView.mj_header endRefreshing];
              
              [MBProgressHUD hideHUDForView:self.view];
          }];
}



#pragma mark - UITableViewDataSource
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    if ([selectStr isEqualToString:@"characterSort"]) {
    
        return self.indexArray;
    }
    else{
        
        return nil;
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    if ([selectStr isEqualToString:@"characterSort"]) {
   
        NSString *key = [self.indexArray objectAtIndex:section];
        
        return key;
    }
    else{
        
        return nil;
    }
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([selectStr isEqualToString:@"characterSort"]) {
    
        return [self.indexArray count];
    }
    else{
        
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([selectStr isEqualToString:@"characterSort"]) {
        
        return [[self.letterResultArr objectAtIndex:section] count] ;
    }
    else{
        
        return self.dataArray.count ;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    VenueVipTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VenueVipTableViewCell"];
    
    NSDictionary *dict;
    
    if ([selectStr isEqualToString:@"characterSort"]) {
    
        //resultArry =[self.letterResultArr objectAtIndex:indexPath.section];
        NSString *name = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        
        NSString *ID = [[name componentsSeparatedByString:@"\\"] lastObject];
        
        dict = [self.dataDict objectForKey:ID];
    }
    else{
        
        //resultArry = self.stringsToSort;
        dict = [self.dataArray objectAtIndex:indexPath.row];
    }
    
    VenueVipModel *venueVipModel = [VenueVipModel mj_objectWithKeyValues:dict];
    
    if ([self.title isEqualToString:@"我的徒弟"]) {
        
        //0 是男
        if ([dict[@"Sex"] integerValue] == 0) {
            
            cell.sexBtn.selected = YES;
        }
        else{
            
            cell.sexBtn.selected = NO;
        }
        
        cell.nickNameLabel.text = venueVipModel.RealName ;
        
        [cell.ageBtn setTitle:[NSString stringWithFormat:@"%ld岁",[Helper getAgeWithBirth:venueVipModel.Birthday]]];
        
        cell.phoneLabel.text = [NSString stringWithFormat:@"联系电话：%@",venueVipModel.CellPhone];
        
        if (venueVipModel.Birthday) {
            [cell.ageBtn setTitle:[NSString stringWithFormat:@"%ld岁",[Helper getAgeWithBirth:venueVipModel.Birthday]]];
        }
        
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:venueVipModel.Avatar imageType:nil]] placeholderImage:PlaceHold];
        
    }else if ([self.title isEqualToString:@"我的粉丝"])
    {
        //0 是男
        cell.sexBtn.hidden = YES;
        
        cell.nickNameLabel.text = venueVipModel.Name ;
        
        cell.phoneLabel.hidden = YES;
        
        cell.ageBtn.hidden = YES;
        
        [cell.rightImageView setImage:nil];
        
        cell.rightImageView.tag = indexPath.row + 100;
        
        [cell.rightImageView addTarget:self action:@selector(attend:) ];
        
        [cell.rightImageView setTitle:@"关注"];
        
        for (NSDictionary *dic in self.attendArr) {
            
            
            
            NSLog(@"%@  == %@",dic[@"MemberID"],venueVipModel.MemberID);
            
            if ([dic[@"MemberID"] integerValue] == [venueVipModel.MemberID integerValue]) {
                
                [cell.rightImageView setTitle:@"取消关注"];
                
                break;
            }
            
        }
        
        
        cell.rightImageView.titleLabel.font = MidBigFont;
        [cell.rightImageView setTitleColor:GrakColor];
        cell.rightImageView.layer.borderWidth = 1;
        cell.rightImageView.layer.borderColor = CSGrayColor.CGColor;
        [cell.rightImageView setContentEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
        
        [cell.headImageView sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:venueVipModel.Pic imageType:nil]] placeholderImage:PlaceHold];
        
    }
    else if ([self.title isEqualToString:@"会员"])
    {
        
        cell.nickNameLabel.text = venueVipModel.Name;
        
        cell.venueVipModel = venueVipModel;
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
    
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    if ([selectStr isEqualToString:@"characterSort"]) {
        
        [self showSectionTitle:title];
        
    }
    
    return index;
}

#pragma mark UITableViewDelegate

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if ([selectStr isEqualToString:@"characterSort"]) {
    
        return 30;
    }
    else{
        
        return 0.00001;
    }
}


-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 0.00001;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return nil;
}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    UITableViewHeaderFooterView *head = (UITableViewHeaderFooterView *)view;
    head.backgroundColor = BackGroundColor;
    [head.textLabel setTextColor:CSColorFromRGB(0x000000)];
    head.textLabel.font = BigFont;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    NSDictionary *dict;
    
    if ([selectStr isEqualToString:@"characterSort"]) {
        
        //resultArry =[self.letterResultArr objectAtIndex:indexPath.section];
        NSString *name = [[self.letterResultArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        
        NSString *ID = [[name componentsSeparatedByString:@"\\"] lastObject];
        
        dict = [self.dataDict objectForKey:ID];
    }
    else{
        
        //resultArry = self.stringsToSort;
        dict = [self.dataArray objectAtIndex:indexPath.row];
    }
    
    
    if ([self.title isEqualToString:@"我的徒弟"]) {
        
        CZQMsterPageVC *master = [CZQMsterPageVC new];
        
        master.dict = dict;
        
        [self.navigationController pushViewController:master animated:YES];
        
        
    }else if ([self.title isEqualToString:@"我的粉丝"])
    {
        
        
    }
    else if ([self.title isEqualToString:@"会员"])
    {
        VenueVipModel *venueVipModel = [VenueVipModel mj_objectWithKeyValues:dict];
        
        VipInfoMainViewController *vipInfoMainVC = [[VipInfoMainViewController alloc] init];
        
        vipInfoMainVC.venueVipModel = venueVipModel;
        
        [self.navigationController pushViewController:vipInfoMainVC animated:YES];
    }
    
}
#pragma mark - UITextFieldDelegate


-(void)textFieldDidEndEditing:(UITextField *)textField
{
    
    
    if ([self.title isEqualToString:@"我的粉丝"]) {
        
        
        
        [self.dataArray removeAllObjects];
        
        
        if ([self.headView.searchView.text isEmptyString]) {
            
            selectStr = @"characterSort";
            
            [self.dataArray addObjectsFromArray:_datArr];
            
        }else
        {
            selectStr = @"search";
            
            for (NSDictionary *dict in _datArr) {
                
                VenueVipModel *venueVipModel = [VenueVipModel mj_objectWithKeyValues:dict];
                
                if ([venueVipModel.Name containsString:self.headView.searchView.text]) {
                    [self.dataArray addObject:dict];
                }
            }
        }
        
        [self.tableView reloadData];
        
    }else
    {
        [self loadData];
    }
    
    
}

#pragma mark - private
- (void)timerHandler:(NSTimer *)sender
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:.3 animations:^{
            self.sectionTitleView.alpha = 0;
        } completion:^(BOOL finished) {
            self.sectionTitleView.hidden = YES;
        }];
    });
}

-(void)showSectionTitle:(NSString*)title{
    
    [self.sectionTitleView setText:title];
    
    self.sectionTitleView.hidden = NO;
    
    self.sectionTitleView.alpha = 1;
    
    [self.timer invalidate];
    
    self.timer = nil;
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandler:) userInfo:nil repeats:NO];
    
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}

#pragma mark 生日提醒

//-(void)sortBtnClick{
//
//    selectStr = @"characterSort";
//    
//    VenueVipTableHeadView *tableHeadView = (VenueVipTableHeadView *)self.tableView.tableHeaderView;
//    
//    [UIView animateWithDuration:0.25 animations:^{
//    
////        tableHeadView.verLineView.centerX = tableHeadView.sortBtn.centerX;
//    }];
//    
//    [self.tableView reloadData];
//}

#pragma mark 续卡提醒

-(void)sortRegBtnClick{
    
    RenewalCardRemindViewController *renewalCard = [RenewalCardRemindViewController new];
    
    [self.navigationController pushViewController:renewalCard animated:YES];
    
//    selectStr = @"regSort";
//
//    VenueVipTableHeadView *tableHeadView = (VenueVipTableHeadView *)self.tableView.tableHeaderView;
//
//    [UIView animateWithDuration:0.25 animations:^{
//
////        tableHeadView.verLineView.centerX = tableHeadView.sortRegBtn.centerX;
//    }];
//
//    [self.tableView reloadData];
}

#pragma mark 添加VIP会员

/**
 添加VIP会员
 */
-(void)addVipMember{
    
    AddVenueVipViewController *addVenueVipVC = [[AddVenueVipViewController alloc] init];

    [self.navigationController pushViewController:addVenueVipVC animated:YES];
}

#pragma mark 过滤
-(void)filterBtnClick{
    
    __weak typeof(self)weakSelf = self;
    
    VipFilterView *vipFilterView = [[VipFilterView alloc] init];
    vipFilterView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    vipFilterView.filterBlock = ^(NSMutableDictionary *filterDict) {
    
        weakSelf.filterDict = filterDict;
        
        
        [weakSelf loadData];
    };
    
    [[UIApplication sharedApplication].keyWindow addSubview:vipFilterView];
}

#pragma mark 右侧按钮点击
-(void)rightBtnClick{
    
    VipBottomAlertView *vipBottomAlertView = [[VipBottomAlertView alloc] init];
    //等级管理
    [vipBottomAlertView.levelBtn addTarget:self action:@selector(stateBtnClick:)];
    //生日提醒
    [vipBottomAlertView.birthBtn addTarget:self action:@selector(birthBtnClick)];
    vipBottomAlertView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [[UIApplication sharedApplication].keyWindow addSubview:vipBottomAlertView];
    self.vipBottomAlertView = vipBottomAlertView;
}


#pragma mark 等级管理
-(void)stateBtnClick:(UIButton *)btn{
    
#warning czq
//    ClassShopStatusViewController *classShopStatusVC = [[ClassShopStatusViewController alloc] init];
//
//    classShopStatusVC.typeStr = @"会员等级";
//
//    classShopStatusVC.title = @"会员等级";
//
//    [self.vipBottomAlertView removeFromSuperview];
//
//    [self.navigationController pushViewController:classShopStatusVC animated:YES];
}

#pragma mark 生日提醒
-(void)birthBtnClick{
    
    [self.vipBottomAlertView removeFromSuperview];
    
    BirthNoticeViewController *birthNoticeVC = [[BirthNoticeViewController alloc] init];
    
    [self.navigationController pushViewController:birthNoticeVC animated:YES];
}

#pragma mark - 关注我的粉丝
-(void)attend:(UIButton *)sender
{
    sender.selected = !sender.selected;
    
    NSString *url;
    
    NSString *tip;
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    VenueVipModel *venueVipModel = [VenueVipModel mj_objectWithKeyValues:[self.dataArray objectAtIndex:sender.tag - 100]];
    
    if ([sender.title isEqualToString:@"关注"]) {
        //关注
        url = Post_Activity_FollowOperate;
        
        tip = @"关注成功";
        
    }else
    {
        //取消关注
        url = Post_Activity_DelFollow;
        
        tip = @"取消关注成功";
        
    }
    
    [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"UserID"] forKey:@"MemberID"];
    
    [params setObject:[[NSUserDefaults standardUserDefaults] valueForKey:@"MasterType"] forKey:@"UserType"];
    
    [params setObject:venueVipModel.ToMemberID forKey:@"ToMemberID"];
    [params setObject:venueVipModel.ToUserType forKey:@"ToUserType"];
    
    
    
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    
    
    [HTTPTool POSTRaw:url parameters:params
     
              success:^(id responseObject){
                  
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  
                  if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                      
                      
                      [MBProgressHUD showText:tip];
                      
                      [MBProgressHUD hideHUDForView:self.view];
                      
                      //刷新数据
                      [self getMasterAttentList];
                  }
                  
              }
     
              failure:^(NSError *error){
                  
                  [MBProgressHUD hideHUDForView:self.view];
              }];
}


#pragma mark Get

-(UILabel *)sectionTitleView{
    
    if (!_sectionTitleView) {
        
        _sectionTitleView = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-100)/2, (SCREEN_HEIGHT-100)/2,100,100)];
        _sectionTitleView.textAlignment = NSTextAlignmentCenter;
        _sectionTitleView.font = [UIFont boldSystemFontOfSize:60];
        _sectionTitleView.textColor = [UIColor blueColor];
        _sectionTitleView.backgroundColor = CSWhiteColor;
        _sectionTitleView.layer.cornerRadius = 6;
        _sectionTitleView.layer.borderWidth = 1.f/[UIScreen mainScreen].scale;
        _sectionTitleView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
        [self.view addSubview:_sectionTitleView];
        _sectionTitleView.hidden = YES;
    }
    
    return _sectionTitleView;
}

-(NSMutableArray *)dataArray{
    
    if (!_dataArray) {
        
        _dataArray = [[NSMutableArray alloc] init];
    }
    
    return _dataArray;
}

-(NSMutableDictionary *)dataDict{
    
    if (!_dataDict) {
        
        _dataDict = [[NSMutableDictionary alloc] init];
    }
    
    return _dataDict;
}

-(NSMutableArray *)stringsToSort{
    
    if (!_stringsToSort) {
        
        _stringsToSort = [[NSMutableArray alloc] init];
    }
    
    return _stringsToSort;
}

-(void)dealloc{
    
    [NotificationCenter removeObserver:self];
}
@end
